package com.services
{
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class LoginService extends BasicService
	{
		public function LoginService(login:String, password:String, busyCursor:Boolean=false, callBack:Function=null)
		{
			var url:String = InteractiveBook.BACKEND_URL + "goldberg/auth/login.xml";
			super(url, "POST", busyCursor, callBack);
			
			var paramters:Object = new Object();
			paramters["login[name]"] = login;
			paramters["login[password]"] = password;
			service.requestTimeout = 30;
			send(paramters);
		}
		
		override public function resultHandler(event:ResultEvent):void
		{
			var user:Object = event.result['goldberg/user'];
			if(user)
			{
				InteractiveBook.userId = user.id.valueOf(); 
			}
			super.resultHandler(event);
		}
		
		override public function faultHandler(event:FaultEvent):void
		{
			if(event.fault.faultString == "Request timed out")
			{
				Alert.show("It seems that the request timed out");
			}
			else
			{
				Alert.show("The username or password given isn't correct");
			}
		}
	}
}